package thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo25 {
    public static void main(String[] args) {
        //创建一个有四个线程的线程池
        // ExecutorService threadPool = Executors.newFixedThreadPool(4);
        ExecutorService threadPool = Executors.newCachedThreadPool();
        for (int i = 0; i < 100; i++) {
            int id = i;
            threadPool.submit(()->{
                System.out.println(id + Thread.currentThread().getName());
            });
        }
        // shutdown方法可以把线程池中的线程全部关闭，但是不能保证线程池中所有线程的任务全部执行完毕
        threadPool.shutdown();
    }
}
